var div = document.getElementsByTagName('div')[0];

// 元素拖拽功能
function drag(elem){
    var elemX,
        elemY;
    elem.addEventListener('mousedown',function(e){
        elemX = e.pageX - parseInt(elem.style.left);
        elemY = e.pageY - parseInt(elem.style.top);
        document.addEventListener('mousemove',move = function(e){
            elem.style.left = e.pageX - elemX + "px";
            elem.style.top = e.pageY - elemY + "px";
        },false)
        document.addEventListener('mouseup',function(){
            document.removeEventListener('mousemove',move,false);
        },false)
    },false)
}
drag(div);

